home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / bltc127.zip / BC_LAI10.C < prev    next >
C/C++ Source or Header  |  1996-11-12  |  7KB  |  252 lines

  1.         
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <string.h>
  6.  
  7. #include "bullet.h"
  8.  
  9. #pragma pack(1)
  10.             
  11. /* --test raw speed using 32-bit long integer key, unique
  12.    1) this test uses a non-standard binary field as a sort field
  13.    2) this code is for raw speed tests--it's straight inline
  14.  
  15.  To compile, just set you compiler to large memory model, have it
  16.  link in BULLET.LIB, and that's it.
  17.  
  18. 12-Nov-96 removed \0\0 from strcpy line
  19.           -- be sure to memset() unused bytes in Bullet structures
  20.  
  21. */
  22.  
  23. struct MemoryPack MP;
  24. struct InitPack IP;
  25. struct ExitPack EP;
  26. struct FieldDescType fieldList[2];
  27. struct CreateDataPack CDP;
  28. struct CreateKeyPack CKP;
  29. struct DosFilePack DFP;
  30. struct OpenPack OP;
  31. struct AccessPack AP;
  32. struct ExitPack EP;
  33.  
  34. int    rez, level;
  35. div_t    div_rez;
  36. time_t  startTime, endTime;
  37.  
  38. char    tmpStr[129];
  39.  
  40. char    nameDat[] = ".\\BINTEST.DBB";
  41. char    nameIx1[] = ".\\BINTEST.IX1";
  42.  
  43. char    kx1[] = "CODENUMBER";
  44.  
  45. unsigned handDat, handIx1;
  46.  
  47. struct TestRecType {
  48.  char  tag;
  49.  long  codeNumber;
  50.  char  codeName[11];
  51. }; /* test program record length=16 bytes */
  52. struct TestRecType testRec;
  53.  
  54. char    keyBuffer[64]; /* MUST supply a work buffer for keys */
  55.                        /* a single one can be shared unless you */
  56.                        /* want to preserve the key buffer for each */
  57.                        /* access pack.  You read a gotten key from */
  58.                        /* here, and also specify key to find here */
  59.                        /* READ THE DOCS on exact matches, et al., */
  60.                        /* especially about "enumerator word", partial */
  61.                        /* match (follow with GetNext/Prev), and so on */
  62.  
  63. long    recs2add;
  64. long    low;
  65. long    high;
  66. long    i;
  67.  
  68. #pragma pack()
  69.  
  70. int main()
  71. {
  72.  
  73. /* implicit is the tag field at the first byte, then comes... */
  74. strncpy(fieldList[0].fieldName, "CODENUMBER",10); // zero-fill
  75. fieldList[0].fieldType = 'B';
  76. fieldList[0].fieldLen = 4;
  77. fieldList[0].fieldDC = 0;
  78. strncpy(fieldList[1].fieldName, "CODENAME",10);  /* must be 0-filled */
  79. fieldList[1].fieldType = 'C';
  80. fieldList[1].fieldLen = 11;   /* 10 and 1 for eos */
  81. fieldList[1].fieldDC = 0;
  82.  
  83. puts("BC_LAI10.C - LONG INT, SIGNED, UNIQUE long int, add/reindex speed test");
  84. puts("-Uses non-standard data files with binary field values, not DBF (in this test)");
  85. puts("-If TMP= defined in environment, reindex routine uses that path for temporary");
  86. puts("workspace, otherwise the current directory is used.\n");
  87.  
  88. level = 100;
  89. MP.func = MEMORYXB;
  90. rez = BULLET(&MP);   /* not really significant */
  91. printf("memory avail   : %lu\n",MP.memory);
  92. if (MP.memory < 40000l) {
  93.    rez = 8;
  94.    goto Abend;
  95. }
  96.  
  97. level = 110;
  98. IP.func = INITXB;
  99. IP.JFTmode = 0;
  100. rez = BULLET(&IP);
  101. if (rez != 0) goto Abend;
  102.  
  103. level = 120;
  104. EP.func = ATEXITXB;
  105. rez = BULLET(&EP);
  106. if (rez != 0) goto Abend;    /* actually, not a fatal error */
  107.  
  108. level = 130;                         /* disregard not found errors */
  109. DFP.func = DELETEFILEDOS;
  110. DFP.filenamePtr = nameDat;
  111. rez = BULLET(&DFP);
  112. DFP.filenamePtr = nameIx1;
  113. rez = BULLET(&DFP);
  114.  
  115. level = 1000;
  116. CDP.func = CREATEDXB;
  117. CDP.filenamePtr = nameDat;
  118. CDP.noFields = 2;
  119. CDP.fieldListPtr = fieldList;
  120. CDP.fileID = 255;
  121. rez = BULLET(&CDP);
  122. if (rez !=0) goto Abend;
  123.  
  124. level = 1010;
  125. OP.func = OPENDXB;
  126. OP.filenamePtr = nameDat;
  127. OP.asMode = READWRITE | DENYNONE;
  128. rez = BULLET(&OP);
  129. if (rez !=0) goto Abend;
  130. handDat = OP.handle;
  131.  
  132. level = 1100;
  133. CKP.func = CREATEKXB;
  134. CKP.filenamePtr = nameIx1;
  135. CKP.keyExpPtr = kx1;
  136. CKP.xbLink = handDat;
  137. CKP.keyFlags = cLONG | cSIGNED | cUNIQUE;
  138. CKP.codePageID = -1;
  139. CKP.countryCode = -1;
  140. CKP.collatePtr = NULL;
  141. rez = BULLET(&CKP);
  142. if (rez !=0) goto Abend;
  143.  
  144. level = 1110;
  145. OP.func = OPENKXB;
  146. OP.filenamePtr = nameIx1;
  147. OP.asMode = READWRITE | DENYNONE;
  148. OP.xbLink = handDat;
  149. rez = BULLET(&OP);
  150. if (rez !=0) goto Abend;
  151. handIx1 = OP.handle;
  152.  
  153. AP.func = ADDRECORDXB;
  154. AP.handle = handDat;
  155. AP.recPtr = &testRec;
  156. AP.keyPtr = keyBuffer;       /* set here and used throughout  */
  157. AP.nextPtr = NULL;
  158.  
  159. testRec.tag = ' ';
  160. strcpy(testRec.codeName, "xxSAME-Oxx");
  161.  
  162. printf("Recs to add/reindex: ");
  163. gets(tmpStr);
  164. recs2add = atol(tmpStr);
  165. if (recs2add == 0L) recs2add = 5L;
  166.  
  167. level = 1200;
  168. low = -3L;
  169. high = low + recs2add - 1L;
  170. printf("Adding %ld records ( keys %ld to %ld )...\n",recs2add,low,high);
  171.  
  172. time(&startTime);
  173. for (i = low; i < (recs2add+low); i++) {
  174.    testRec.codeNumber = i;
  175.    rez = BULLET(&AP);
  176.    if (rez !=0) goto Abend;
  177. }
  178. time(&endTime);
  179. printf("...took %lu secs.\n",(endTime - startTime));
  180.  
  181. level = 1210;
  182. printf("Reindexing...\n");
  183. AP.func = REINDEXXB;
  184. AP.handle = handIx1;
  185. time(&startTime);
  186. rez = BULLET(&AP);
  187. time(&endTime);
  188. if (rez != 0) {
  189.    rez = AP.stat;    /* MUST take AP.stat since a xaction routine */
  190.    goto Abend;       /* see docs and !README2.TXT for more */
  191. }
  192. printf("...took %lu secs\n\n",(endTime - startTime));
  193.  
  194. level = 1300;
  195. AP.func = GETFIRSTXB;
  196. rez = BULLET(&AP);
  197. printf("  The first 5 key/recs  (recNo --- key - data)\n");
  198. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  199. for (i=1;i < 5; i++) {
  200.    if (rez != 0) break;
  201.    AP.func = GETNEXTXB;
  202.    rez = BULLET(&AP);
  203.    printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  204. }
  205. if (rez == 202) rez = 0;
  206. if (rez != 0) goto Abend;
  207. puts(" ");
  208.  
  209. level = 1310;
  210. AP.func = GETLASTXB;
  211. rez = BULLET(&AP);
  212. printf("  The last 5 key/recs\n");
  213. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  214. for (i=1;i < 5; i++) {
  215.    if (rez != 0) break;
  216.    AP.func = GETPREVXB;
  217.    rez = BULLET(&AP);
  218.    printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  219. }
  220. if (rez == 203) rez = 0;
  221. if (rez != 0) goto Abend;
  222.  
  223. level = 1311;
  224. printf("  Finding the last gotten key, (in AP.keybuffer already)\n");
  225. AP.func = GETEQUALXB;
  226. rez = BULLET(&AP);
  227. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  228. if (rez != 0) goto Abend;
  229.  
  230. level = 1312;
  231. printf("  Finding key of 5\n");
  232. AP.func = GETEQUALXB;
  233. *((long *)keyBuffer) = 5L;
  234. rez = BULLET(&AP);
  235. printf("%7lu %7ld %.10s\n",AP.recNo,testRec.codeNumber,testRec.codeName);
  236. if (rez != 0) goto Abend;
  237.  
  238. puts("Okay.");
  239. EP.func = EXITXB;
  240. rez = BULLET(&EP);
  241. return(0);
  242. /* program exit */
  243.  
  244.  
  245. /*----------------------------------------------*/
  246. /* that's right, we go to a termination routine */
  247.  
  248. Abend:
  249.    printf("Error: %u at level %u while performing ",rez,level);
  250.    exit(1);
  251. }
  252.